package se.su.dsv.theclient;

import theserver.VenueActivity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class SocialVenueList extends ListActivity {
	private VenueActivity activity = null;
	private String[] venues = new String[]{};
	private ClientDBAdapter dbHelper;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
		dbHelper = new ClientDBAdapter(this);
		dbHelper.open();
		fillData();
	}

    private void fillData() {
        // Get all of the rows from the database and create the item list
        Cursor venueCursor = dbHelper.fetchAllVenues();
        startManagingCursor(venueCursor);
        
        // Create an array to specify the fields we want to display in the list (only TITLE)
        String[] from = new String[]{ClientDBAdapter.KEY_VENUE_NAME};
        
        // and an array of the fields we want to bind those fields to (in this case just text1)
        int[] to = new int[]{R.id.venuename};
        
        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter notes = 
        	    new SimpleCursorAdapter(this, R.layout.venue_row, venueCursor, from, to);
        setListAdapter(notes);
    }
	
	public void onListItemClick(ListView l, View v, int position, long id) {
		getListView().getItemAtPosition(position);
		//getListView().getItemAtPosition(position);
		super.onListItemClick(l, v, position, id);
		Intent i = new Intent(this, SocialActivityList.class);
		//i.putExtra(NotesDbAdapter.KEY_ROWID, id);
		//startActivityForResult(i, ACTIVITY_EDIT);
		startActivity(i);
	}
}
